#include "startupdatatext.h"
#include <QDebug>
#include <string>

StartUpdataText::StartUpdataText(QObject *parent) : QThread(parent)
{
 this->pListObj = nullptr;
}

void StartUpdataText::run()
{
    if(pListObj == nullptr)
        return;

    //这点开始前台特效
    {
        QList<std::string>::iterator result_iter1 = pListObj->begin();
        QTime oldedTime = QTime::currentTime();
        while(true)//执行20秒的特效时间
        {
            QThread::currentThread()->msleep(100);
                emit SendUpdataText(tr((*(result_iter1++)).c_str()), true);
                //ui->label->setText(tr((*(result_iter1++)).c_str()));
                if(result_iter1 == pListObj->end())
                    result_iter1 = pListObj->begin();

                QTime curTime = QTime::currentTime();
                int n = oldedTime.msecsTo(curTime);
                if(n >= 10000)
                    break;
        }

        qDebug() << (*result_iter1).c_str();
        if(*result_iter1 != *result_iter)
        {
            //启动补救计划
            QTime runTime = QTime::currentTime();
            while(true)
            {
                    //ui->label->setText(tr((*(result_iter1)).c_str()));

                    QThread::currentThread()->msleep(100);
                    if(*result_iter1 == *result_iter)
                    {
                        emit SendUpdataText(tr((*(result_iter1++)).c_str()), false);
                        break;
                    }else
                        emit SendUpdataText(tr((*(result_iter1++)).c_str()), true);

                    if(result_iter1 == pListObj->end())
                        result_iter1 = pListObj->begin();
                    runTime = QTime::currentTime();
            }
        }
        else
        {
            emit SendUpdataText(tr((*(result_iter1++)).c_str()), false);
        }
    }
}

void StartUpdataText::SetVarable(QList<std::string> *pListObj, QList<std::string>::iterator result_iter)
{
    this->pListObj = pListObj;
    this->result_iter = result_iter;
    qDebug() << (*result_iter).c_str();
}
